# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=usb-modeswitch
pkgver=2.6.0
pkgrel=1
_pkgdata=20170806
pkgdesc="A mode switching tool for controlling flip flop (multiple device) USB gear"
url="http://www.draisberghof.de/usb_modeswitch/"
arch="all"
license="GPL-2.0-or-later"
makedepends="libusb-compat-dev coreutils"
subpackages="$pkgname-doc $pkgname-udev"
options="!check" # no testsuite
source="http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-$pkgver.tar.bz2
		http://www.draisberghof.de/usb_modeswitch/$pkgname-data-$_pkgdata.tar.bz2
		usb_modeswitch.setup"

prepare() {
	make clean
	sed -i -e 's/--mode=/-m/' Makefile

	cd ../$pkgname-data-$_pkgdata
	# sed -i -e 's%install -m644 -t $(PREFIX)/share/usb_modeswitch ./usb_modeswitch.d/*%cp -R $(PREFIX)/share/usb_modeswitch/* ./usb_modeswitch.d/%' Makefile
	sed -i -e 's/--mode=/-m/' Makefile
}

build() {
	make
}

package() {
	make DESTDIR="$pkgdir" install

	# installing data
	cd $srcdir/usb-modeswitch-data-$_pkgdata
	make DESTDIR=$pkgdir install
	# installing config
	cp $srcdir/usb_modeswitch.setup $pkgdir/etc/
}

udev() {
	pkgdesc="udev support for usb-modeswitch"
	depends="eudev tcl $pkgname=$pkgver-r$pkgrel"
	mkdir -p "$subpkgdir"/usr/sbin
	mv "$pkgdir"/lib "$subpkgdir"/
	mv "$pkgdir"/usr/sbin/usb_modeswitch_dispatcher \
		"$subpkgdir"/usr/sbin/
}

sha512sums="43e6d885380602ddaaf771af73a302a7de30f7ae6ea58b2b572a9ad9ec77a453789020595de33a8b04ec209414fe08face2bbf84c67271d7b6b90700face09ef  usb-modeswitch-2.6.0.tar.bz2
818bc9f3d9b75df245bb25f959075041667607e7681bdbca7006ec036613130a0fa5e41da9e939ca510e524a78a7a76aef82ecfbbe19611887b3735987b951cc  usb-modeswitch-data-20170806.tar.bz2
48bc921849c529059c35f00e9cb10e92fee32622d63291bbd7184039bbe4c4324591b4011b24cf9b6c4ed2a7ad90fe0d5287a58631de5114b36f70d4f6f3c250  usb_modeswitch.setup"
